package com.empire.module.spider.service.lotteryfootballmatch500wan;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.spider.controller.app.lotteryfootballmatch500wan.vo.*;
import com.empire.module.spider.dal.dataobject.lotteryfootballmatch500wan.LotteryFootballMatch500wanDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.spider.dal.mysql.lotteryfootballmatch500wan.LotteryFootballMatch500wanMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.spider.enums.ErrorCodeConstants.*;

/**
 * 足彩比赛 Service 实现类
 *
 * @author 无敌
 */
@Service
@Validated
public class LotteryFootballMatch500wanServiceImpl implements LotteryFootballMatch500wanService {

    @Resource
    private LotteryFootballMatch500wanMapper lotteryFootballMatch500wanMapper;

    @Override
    public String createLotteryFootballMatch500wan(AppLotteryFootballMatch500wanSaveReqVO createReqVO) {
        // 插入
        LotteryFootballMatch500wanDO lotteryFootballMatch500wan = BeanUtils.toBean(createReqVO, LotteryFootballMatch500wanDO.class);
        lotteryFootballMatch500wanMapper.insert(lotteryFootballMatch500wan);
        // 返回
        return lotteryFootballMatch500wan.getFid();
    }

    @Override
    public void updateLotteryFootballMatch500wan(AppLotteryFootballMatch500wanSaveReqVO updateReqVO) {
        // 校验存在
        validateLotteryFootballMatch500wanExists(updateReqVO.getFid());
        // 更新
        LotteryFootballMatch500wanDO updateObj = BeanUtils.toBean(updateReqVO, LotteryFootballMatch500wanDO.class);
        lotteryFootballMatch500wanMapper.updateById(updateObj);
    }

    @Override
    public void deleteLotteryFootballMatch500wan(String id) {
        // 校验存在
        validateLotteryFootballMatch500wanExists(id);
        // 删除
        lotteryFootballMatch500wanMapper.deleteById(id);
    }

    private void validateLotteryFootballMatch500wanExists(String id) {
        if (lotteryFootballMatch500wanMapper.selectById(id) == null) {
            throw exception(LOTTERY_FOOTBALL_MATCH500WAN_NOT_EXISTS);
        }
    }

    @Override
    public LotteryFootballMatch500wanDO getLotteryFootballMatch500wan(String id) {
        return lotteryFootballMatch500wanMapper.selectById(id);
    }

    @Override
    public PageResult<LotteryFootballMatch500wanDO> getLotteryFootballMatch500wanPage(AppLotteryFootballMatch500wanPageReqVO pageReqVO) {
        return lotteryFootballMatch500wanMapper.selectPage(pageReqVO);
    }

}
